package com.viphuli.http.handler;

import java.util.List;

import android.support.v4.app.Fragment;
import android.widget.TabWidget;
import android.widget.TextView;

import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.daimajia.slider.library.SliderTypes.TextSliderView;
import com.viphuli.app.R;
import com.viphuli.common.Constants;
import com.viphuli.common.Constants.ActionType;
import com.viphuli.fragment.HomeServiceInfoFragment;
import com.viphuli.fragment.HomeServiceInfoFragment.InfoTabEnum;
import com.viphuli.fragment.HomeServiceInfoIntroduceFragment;
import com.viphuli.fragment.HomeServiceInfoNeedKnowFragment;
import com.viphuli.http.bean.page.HomeRoomServiceItemPage;
import com.viphuli.http.bean.part.HomeTopSlide;

public class HomeServiceInfoHandler extends MyBaseHttpResponseHandler<HomeServiceInfoFragment, HomeRoomServiceItemPage> {
	private static final String URL = "url";
	public static final String TITLE = "title";

	@Override
	public void deal() {

		//顶部轮转图
		List<HomeTopSlide> topSlides = page.getTopSlide();

		if (topSlides != null && topSlides.size() == 1) {
			caller.getSlider().stopAutoCycle();
		} else {
			caller.getSlider().setDuration(Constants.TOP_SLIDE_DURATION);
		}

		for (HomeTopSlide topSlide : topSlides) {

			TextSliderView textSliderView = new TextSliderView(caller.getActivity());

			textSliderView.//
					description(topSlide.getTitle()).//标题
					image(topSlide.getPic()).//图片
					setScaleType(BaseSliderView.ScaleType.Fit);

			//add your extra information
			if (ActionType.none.getType() == topSlide.getActionType()) {
				
				textSliderView.getBundle().putString(TITLE, topSlide.getTitle());
				caller.getSlider().addSlider(textSliderView);
				
			}
			

		}

		//标签TAB
		TabWidget tabWidget = caller.getTabHost().getTabWidget();
		for (int i = 0; i < tabWidget.getChildCount(); i++) {

			if (i == 1) {
				TextView textView = (TextView) tabWidget.getChildAt(i).findViewById(R.id.id_main_home_service_item_info_tab_text);
				textView.setText(InfoTabEnum.comment.getName() + "(" + page.getCommentCount() + ")");
			}
		}

		Fragment frag = caller.getActivity().getSupportFragmentManager().findFragmentById(R.id.id_main_home_service_item_info_content);
		//			Fragment frag = caller.getActivity().getSupportFragmentManager().findFragmentByTag(ServiceItemInfoTabEnum.needKnow.getName());
		if (frag.isAdded() && page != null) {
			if (frag instanceof HomeServiceInfoIntroduceFragment) {

				HomeServiceInfoIntroduceFragment introduceFrag = (HomeServiceInfoIntroduceFragment) frag;
				introduceFrag.setIntroduce(page.getIntroduction());

			} else if (frag instanceof HomeServiceInfoNeedKnowFragment) {

				HomeServiceInfoNeedKnowFragment needKnowFrag = (HomeServiceInfoNeedKnowFragment) frag;
				needKnowFrag.setNeedKnow(page.getNotice());

			}

		}

		caller.setItemPage(page);

	}

}
